<template>
  <div>
    <TopFilter :list="topFilterList" :collapse="false" @filterChange="changeHandle"
               @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      height="400"
      :selectionType="selectionType"
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchApi"
      :isMemoryPagination="true"
      datakey="records"
      :onColumnsChange="columns => (this.columns = columns)"
      :onSyncTableData="tableChangeFun"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>
    <div class="dialogBottmView">
      <el-button size="small" type="primary" class="btnStyle" @click="submitBtn">确定
      </el-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeDialog">取消
      </el-button>
    </div>
  </div>
</template>

<script>
  import {dictionary} from '@/utils/dictMixin';
  import {getCar,findPdiList} from '@/api/serviceass/pdimanage/meetingcar';
  export default {
    name: 'Vehicle',
    components: {},
    mixins: [dictionary],
    data() {
      this.BaseTable = null;
      return {
        topFilterList: this.createTopFilterList(),
        visible: false,
        fetchParams: {dealerCode:''},
        columns: this.createTableColumns(),
        selectArr: [],
        fetchApi:getCar,
        faechparamsbyvin:{}
      };
    },
    props: {
      selectionType: {},
      params: {
        type: Object,
        default() {
          return {}
        }
      },
      rowData: {
        type: Object,
        default: () => ({})
      }
    },
    created() {
      this.fetchParams.dealerCode = this.rowData.dealerCode
    },
    mounted() {
      this.BaseTable = this.$refs.table.$refs.pageTable;
    },
    methods: {
      tableChangeFun(val) {
      },
      selectChange(val) {
        this.selectArr = val
      },
      createTableColumns() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 70,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            width: 170,
            title: 'VIN',
            dataIndex: 'vin',
            sorter: true,
          },
          {
            title: '车型',
            dataIndex: 'modelName',
            sorter: true,
          },
          {
            title: '电机编号',
            dataIndex: 'motorNo',
            sorter: true,
          },
          {
            title: '电机型号',
            dataIndex: 'motorModel',
            sorter: true,
          },
          {
            title: '发动机号',
            dataIndex: 'engineNo',
            sorter: true,
          },
          {
            title: '生产日期',
            dataIndex: 'productDate',
            sorter: true,
          },
          {
            title: '车辆状态',
            dataIndex: 'vehicleStatus',
            sorter: true,
            dictItems: this.createDictList(6040),
          },
          {
            title: '经销商代码',
            dataIndex: 'dealCode',
            sorter: true,
          },
          {
            title: '经销商名称',
            dataIndex: 'dealName',
            sorter: true,
          }
        ]
      },
      createTopFilterList() {
        return [
          {
            type: 'INPUT',
            label: 'VIN',
            fieldName: 'vin',
            placeholder: '车辆唯一识别代码...'
          }
        ];
      },

      collapseHandle() {
        this.$nextTick(() => {
          this.BaseTable.EXECUTE_RESET_HEIGHT();
        });
      },

      changeHandle(val) {
        this.faechparamsbyvin = Object.assign({}, val,this.fetchParams);
        getCar(this.faechparamsbyvin).then(res=>{
          this.$refs.table.SET_TABLE_DATA(res.data)
        })
      },


      closeHandler(val, type) {
        this.visible = val;
        if (type === 'refresh') {
          // 重新加载
          this.fetchParams = {...this.fetchParams};
        }
      },
      closeDialog() {
        this.$emit('closeDialog')
      },
      submitBtn() {
        if (this.selectArr.length == 0) {
          this.$notify.warning({title: '提示信息', message: '请您选择车辆'});
          return
        }
        findPdiList({vin:this.selectArr[0].vin}).then(response=>{
          if (response.data.length>0){
            this.$notify.warning({title: '提示信息', message: '该车辆已经做过PDI'});
          }else{
            this.$emit('selectArr', this.selectArr)
          }
        })
      }
    }
  };
</script>

<style lang="less" scoped>
  .dialogBottmView {
    text-align: center;
  }
</style>
